﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using SqlCon;


namespace yfxt
{
    public partial class xxwh_ypxx : Form
    {

        public string s_temp;
        public string S_temp
        {
            get { return s_temp; }
            set { this.s_temp = value; }
        }


        int i = 0;//标志
        public xxwh_ypxx()
        {
            InitializeComponent();
        }
        SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction);
        private void button2_Click(object sender, EventArgs e)
        {
            string s_ = "select ypmc,ypgg,ypdw,gcsl,dcsl,(case zfpb when '0' then '否' when '1' then '是' end) as zfpb,pydm,yk_typk.ypxh " +
                         " from yf_kcmx,yk_typk " +
                         " where yf_kcmx.ypxh=yk_typk.ypxh and pydm like  '" + textBox1.Text.ToString().Trim() + "%'" +
                         " group by ypmc,ypgg,ypdw,gcsl,dcsl,zfpb,pydm,yk_typk.ypxh ";
            if (conn.State != ConnectionState.Open) { conn.Open(); }

            using (SqlCommand cmd = new SqlCommand(s_, conn))
            {
                SqlDataAdapter da = new SqlDataAdapter();

                da.SelectCommand = cmd;

                DataTable dt = new DataTable();

                da.Fill(dt);

                dataGridView1.DataSource = dt;
            }


            dataGridView1.Columns[0].HeaderCell.Value = "药品名称";

            dataGridView1.Columns[1].HeaderCell.Value = "药品规格";

            dataGridView1.Columns[2].HeaderCell.Value = "药房单位";

            dataGridView1.Columns[3].HeaderCell.Value = "高储存";

            dataGridView1.Columns[4].HeaderCell.Value = "低储存";

            dataGridView1.Columns[5].HeaderCell.Value = "是否作废";

            dataGridView1.Columns[6].HeaderCell.Value = "拼音代码";

            dataGridView1.Columns[7].HeaderCell.Value = "药库编码";


        }

        private void xxwh_ypxx_Load(object sender, EventArgs e)
        {
            string s_ = "select ypmc,ypgg,ypdw,gcsl,dcsl,(case zfpb when '0' then '否' when '1' then '是' end) as zfpb,pydm,yk_typk.ypxh  " +
                         " from yf_kcmx,yk_typk " +
                         " where yf_kcmx.ypxh=yk_typk.ypxh" +
                         " group by ypmc,ypgg,ypdw,gcsl,dcsl,zfpb,pydm,yk_typk.ypxh ";
            if (conn.State != ConnectionState.Open) { conn.Open(); }

            using (SqlCommand cmd = new SqlCommand(s_, conn))
            {
                SqlDataAdapter da = new SqlDataAdapter();

                da.SelectCommand = cmd;

                DataTable dt = new DataTable();

                da.Fill(dt);

                dataGridView1.DataSource = dt;
            }


            dataGridView1.Columns[0].HeaderCell.Value = "药品名称";

            dataGridView1.Columns[1].HeaderCell.Value = "药品规格";

            dataGridView1.Columns[2].HeaderCell.Value = "药房单位";

            dataGridView1.Columns[3].HeaderCell.Value = "高储存";

            dataGridView1.Columns[4].HeaderCell.Value = "低储存";

            dataGridView1.Columns[5].HeaderCell.Value = "是否作废";

            dataGridView1.Columns[6].HeaderCell.Value = "拼音代码";

            dataGridView1.Columns[7].HeaderCell.Value = "药库编码";




        }


        private void textBox1_KeyUp(object sender, KeyEventArgs e)
        {
            string s_ = "select ypmc,ypgg,ypdw,gcsl,dcsl,(case zfpb when '0' then '否' when '1' then '是' end) as zfpb,pydm,yk_typk.ypxh " +
                         " from yf_kcmx,yk_typk " +
                         " where yf_kcmx.ypxh=yk_typk.ypxh and pydm like  '" + textBox1.Text.ToString().Trim() + "%'" +
                         " group by ypmc,ypgg,ypdw,gcsl,dcsl,zfpb ,pydm,yk_typk.ypxh";
            if (conn.State != ConnectionState.Open) { conn.Open(); }

            using (SqlCommand cmd = new SqlCommand(s_, conn))
            {
                SqlDataAdapter da = new SqlDataAdapter();

                da.SelectCommand = cmd;

                DataTable dt = new DataTable();

                da.Fill(dt);

                dataGridView1.DataSource = dt;
            }


            dataGridView1.Columns[0].HeaderCell.Value = "药品名称";

            dataGridView1.Columns[1].HeaderCell.Value = "药品规格";

            dataGridView1.Columns[2].HeaderCell.Value = "药房单位";

            dataGridView1.Columns[3].HeaderCell.Value = "高储存";

            dataGridView1.Columns[4].HeaderCell.Value = "低储存";

            dataGridView1.Columns[5].HeaderCell.Value = "是否作废";

            dataGridView1.Columns[6].HeaderCell.Value = "拼音代码";

            dataGridView1.Columns[7].HeaderCell.Value = "药库编码";

        }

        private void dataGridView1_SelectionChanged(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            s_temp = dataGridView1.CurrentRow.Cells["ypxh"].Value.ToString();

            xxwh_ypxx_xg ypxx_xg = new xxwh_ypxx_xg();

            ypxx_xg.Owner = this;

            ypxx_xg.Show();



            //MessageBox.Show(dataGridView1.CurrentRow.Cells["ypxh"].Value.ToString());
        }

        private void button5_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            //s_temp = textBox1.Text.ToString();

            //xxwh_dy dy = new xxwh_dy();

            //dy.Owner = this;

            //dy.Show();
        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {



            button3_Click(sender, e);


        }
    }
}
